/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.gruposicom.view.utils;

import ar.com.gruposicom.domain.TrueValue;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author marcelo
 */
public class UIDefineAceptableValuesUtils 
{

    private UIAddCommandUtils commandsUtil;
    private Collection<TrueValue> values = new ArrayList<>();
    private TrueValue value;
    
    public UIDefineAceptableValuesUtils() 
    {
    }

    public UIAddCommandUtils getCommandsUtil() {
        return commandsUtil;
    }

    public void setCommandsUtil(UIAddCommandUtils commandsUtil) {
        this.commandsUtil = commandsUtil;
    }

    public TrueValue getValue() {
        return value;
    }

    public void setValue(TrueValue value) {
        this.value = value;
    }
    
    public void addValue(String val, String dataType, String comprobation, JTable table)
    {
        this.value = new TrueValue();
        this.value.setDataType(dataType.trim());
        this.value.setRuleComparation(comprobation.trim());
        this.value.setValue(val);
        DefaultTableModel model = (DefaultTableModel)table.getModel();
        String data[] = new String[3];
        data[0] = "";
        data[1] = value.getValue();
        data[2] = value.getRuleComparation();
        model.addRow(data);
        this.values.add(value);
    }
    
    private void cleanTable(JTable table)
    {
        DefaultTableModel modelo = (DefaultTableModel)table.getModel();
        while(table.getRowCount() != 0)
                modelo.removeRow(0);
        modelo = null;
    }
    
    public void addValues()
    {
        System.out.println("Se definieron "+values.size()+" valores");
        this.commandsUtil.setValues(values);
    }
    
}
